package com.trailwalker.javafx.utils.screen;

import com.trailwalker.JavaUtils.log.LogUtils;
import javafx.geometry.Rectangle2D;
import javafx.stage.Screen;

/**
 * @author Trailwalker
 * @create 2021-08-31 17:09
 * @des
 */
public class ScreenUtils {

    private static final String TAG = ScreenUtils.class.getSimpleName();

    private static ScreenUtils mScreenUtils;
    private final Screen mPrimaryScreen;
    private final Rectangle2D mBounds;
    private final Rectangle2D mVisualBounds;

    private ScreenUtils() {
        mPrimaryScreen = Screen.getPrimary();
        mBounds = mPrimaryScreen.getBounds();
        mVisualBounds = mPrimaryScreen.getVisualBounds();
        LogUtils.log(TAG, "屏幕信息:");
        LogUtils.log(TAG, "全部区域:");
        LogUtils.log(TAG, "左上角 x:" + mBounds.getMinX() + " y:" + mBounds.getMinY());
        LogUtils.log(TAG, "又下角 x:" + mBounds.getMaxX() + " y:" + mBounds.getMaxY());
        LogUtils.log(TAG, "宽度:" + mBounds.getWidth() + " 高度:" + mBounds.getHeight());
        LogUtils.log(TAG, "可视区域:");
        LogUtils.log(TAG, "左上角 x:" + mVisualBounds.getMinX() + " y:" + mVisualBounds.getMinY());
        LogUtils.log(TAG, "又下角 x:" + mVisualBounds.getMaxX() + " y:" + mVisualBounds.getMaxY());
        LogUtils.log(TAG, "宽度:" + mVisualBounds.getWidth() + " 高度:" + mVisualBounds.getHeight());
        double dpi = mPrimaryScreen.getDpi();
        LogUtils.log(TAG, "dpi:" + dpi);
    }

    public static ScreenUtils getInstance() {
        if (mScreenUtils == null) {
            mScreenUtils = new ScreenUtils();
        }
        return mScreenUtils;
    }

    /**
     * 获取屏幕宽度
     *
     * @return
     */
    public double getWidth() {
        return mBounds.getWidth();
    }

    /**
     * 获取屏幕高度
     *
     * @return
     */
    public double getHeight() {
        return mBounds.getHeight();
    }

}
